String.prototype.startsWith = function(str){
    return (this.indexOf(str) === 0);
}

function sp(string){
	a=string.split(':');
	a.splice(0,1);
	return a.join(':');
}

function parse_photo_response(input){
	
	array=input.split('||||');
	photo_array=new Array();
	for( i=0 ; i < array.length ; i++  ){
		value=array[i];
		if (value.startsWith('original_filename') )
			photo_array['original_filename'] = sp(value);
		else if  (value.startsWith('name') )
			photo_array['name'] = sp(value);
		
		else if  (value.startsWith('model') )
			photo_array['model'] = sp(value);
		
		else if  (value.startsWith('exposure') )
			photo_array['exposure'] = sp(value);
		
		else if  (value.startsWith('fnumber') )
			photo_array['fnumber'] = sp(value);
		
		else if  (value.startsWith('date') )
			photo_array['date'] = sp(value);
		
		else if  (value.startsWith('lensmake') )
			photo_array['lensmake'] = sp(value);
		
		else if  (value.startsWith('ISO') )
			photo_array['ISO'] = sp(value);
		
		else if  (value.startsWith('flash') )
			photo_array['flash'] = sp(value);
		
		else if  (value.startsWith('coordinates') )
			photo_array['coordinates'] = sp(value);
		
		else if  (value.startsWith('id') )
			photo_array['id'] = sp(value);
		
	}


	return photo_array;
}

function create_photo_form(photo){
	html='';
	
	value=photo;
	ID=photo.IDdiv;
	html+="<img src='./uploads/thumbs/"+photo.name+"' height='100px' class='floatRight' /> ";

	html+='<label for="name">'+lang.photo_name+'</label>'+
			'<input type="text" name="name-'+ID+'" id="name-'+ID+'" class="text_field small"> <br>'+
			'<label for="descr-'+ID+'">'+lang.photo_descr+'</label>'+
			'<textarea name="descr-'+ID+'" id="descr-'+ID+'" rows=2 cols=30></textarea><br> '+
			'<a href="show_cats_div('+ID+');" >'+lang.upload_show_cats+'</a><br>';
	if (isUndefined(value.coordinates))
		html+='<a href="show_map_div('+ID+');" >'+lang.upload_show_map_nonexistent+'</a><br>';
	else 
		html+='<a href="show_map_div('+ID+');" >'+lang.upload_show_map_existent+'</a><br>';

	/*	
	if  (!isUndefined(value.model) ){
		html+=lang.photo_model+
				'<input type="text" name="model'+ID+'" id="model'+ID+'"> <br>';
	}
	if  (!isUndefined(value.date)){
		html+=lang.photo_date+
				'<input type="text" name="date'+ID+'" id="date'+ID+'" > <br>' ;

	}
	*/
	//html+= lang.photo_select_categories+'<br>';
	
	
		
	


	return html;
			
} 

function show_cats_div(ID){
	html='<table class="table_clear">'
	
}
function show_map_div(ID){
	
}

function isUndefined(x){
	return x == null && x !== null; 
}

